package com.cgq.controller;

import com.cgq.pojo.Stock;
import com.cgq.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/**
 * *  Author:陈国强
 * *  Description:
 * *  Date:2023/2/15 14:41
 */
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService service;


    @GetMapping("/getCount/{product_code}")
    public String deduct(@PathVariable String product_code){
        return service.deduct(product_code);
    }


    @GetMapping("/getCount1/{product_code}/{count}")
    public String deduct1(@PathVariable String product_code,@PathVariable Integer count){
        return service.deduct1(product_code,count);
    }

    //悲观锁演示
    @GetMapping("/getCount2/{productCode}")
    public List<Stock> deduct2(@PathVariable String productCode){
        List<Stock> stocks = service.queryStock(productCode);
        return stocks;
    }

    //乐观锁演示
    @GetMapping("/getCount3/{productCode}")
    public List<Stock> deduct3(@PathVariable String productCode){
        List<Stock> stocks = service.queryStock1(productCode);
        return stocks;
    }

}
